package com.javaenzk.wfx.manager.service.impl;


import com.javaenzk.wfx.manager.dao.GoodsMapper;
import com.javaenzk.wfx.manager.po.Wxb_Good;
import com.javaenzk.wfx.manager.po.Wxb_Good_Sku;
import com.javaenzk.wfx.manager.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class GoodsServiceImpl implements IGoodsService {

    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public List<Wxb_Good> queryGoodsList() {
        List<Wxb_Good> wxbGoods = goodsMapper.queryAllGoods();
        return wxbGoods;
    }

    /**
     * 事务传播性：service层的方法1上有声明式事务，方法2上也有声明式事务。
     * 方法1调用方法2：那方法1和方法2中的事务可以是同一个，也可以是独立的事务。这种现象就是事务的传播性
     * @param goodsId
     * @return
     */
    @Transactional(readOnly=true)
    public List<Wxb_Good_Sku> querySkuListByGoodsId(String goodsId) {
        List<Wxb_Good_Sku> wxbGoodSkus = goodsMapper.querySkuListByGoodsId(goodsId);
        return wxbGoodSkus;
    }

    @Transactional(readOnly=true)
    public Wxb_Good queryGoodsById(String goodsId){
        Wxb_Good wxbGood = goodsMapper.queryGoodsById(goodsId);

        //查询商品套餐
        List<Wxb_Good_Sku> wxbGoodSkus = querySkuListByGoodsId(goodsId);

        //一对多关系集合
        wxbGood.setSkulist(wxbGoodSkus);

        return wxbGood;
    }

}
